package com.example.sys.Controller;

import com.example.sys.Entity.StudentInfo;
import com.example.sys.Service.StudentInfoService;
import com.example.sys.Vo.StudentInfoClassInfo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("stu")
public class StudentInfoController {

    @Autowired
    private StudentInfoService studentInfoService;

    //http://localhost:8080/stu/query  get   name
    @GetMapping("/query")
    public List<StudentInfo> queryStudentInfoByName( String name ){
        return  studentInfoService.getAllStudentInfo(name);
    }

    //http://localhost:8080/stu/querystu get name
    @GetMapping("querystu")
    public List<StudentInfoClassInfo> queryStudentInfoAndClassInfoByName(@RequestParam String name, @RequestParam Integer clsid) {
        List<StudentInfoClassInfo> stuClass = null;
        if (clsid == 0) {
            stuClass = studentInfoService.getAllStuAndClassByName(name);
        } else {
            stuClass = studentInfoService.getAllStuAndClassByclsAndName(name, clsid);
        }
        return stuClass;
    }

    //http://localhost:8080/stu/del/197
    @GetMapping("del/{id}")
    private Integer delStudentInfo(@PathVariable Integer id) {
        return studentInfoService.deleteByID(id);
    }
    //http://localhost:8080/stu/add
    @PostMapping("add")
    public Integer addStudentInfo(@RequestBody StudentInfo studentInfo) {
       Integer i = studentInfoService.insertStudentInfo(studentInfo);
        return i;
    }
    @PostMapping("update")
    public Integer updateStudentInfo(@RequestBody StudentInfo studentInfo) {
        Integer i = studentInfoService.updateStudentInfo(studentInfo);
        return i;
    }

 @GetMapping("page")
    public PageInfo<StudentInfoClassInfo> pageStudentInfoClassInfo(@RequestParam Integer page,@RequestParam Integer size) {
        return studentInfoService.getPageStudentInfoClassInfo(page,size);
 }
}
